<template>
	<view class="main">
		<!-- 管理后台扫码充值 -->
		<view class="input_box"><input type="text" class="input" placeholder="请输入充值金额" v-model="total_fee" /></view>
		<view class="btn" :style="{ '--color': vuex_config.themeColor1 }">立即充值</view>

		<sww-login></sww-login>
	</view>
</template>

<script>
import { wxPay } from '@/utils/weixinPay';
import {AddNewData} from '@/common/http.request.js'
export default {
	components: {},
	data() {
		return {
			total_fee: null,
			purchaser:null, // 共享id
		};
	},
	onLoad(options) {
		this.purchaser = Number(options.purchaser)
	},

	methods: {
		submit() {
			if (this.loading) {
				return;
			}
			this.$login()
				.then(() => {
					this.loading = true;
					let params = {
						prodName: '在线充值',
						total_fee: total_fee,
						order_no: this.getNum()
					};
					wxPay(params).then(() => {
						this.loading = false;
						this.$loading()
						this.addpurchaser(params)
					});
				})
				.catch(() => {
					this.loading = false;
				});
		},
		addpurchaser (obj) {
			let params = {
				type: 5,
			  fk_purchaser_id: this.purchaser,
			  serial_number: obj.order_no,
			  fk_order_id: 0,
			  price: obj.total_fee,
			  pay_type: 4,
			  remark: '小程序扫码在线充值',
			  pay_status: 1,
			}
			AddNewData('b_product_purchaser_consume',params).then(()=>{
				this.$hide()
				this.$toast('充值成功')
			})
		},
		getNum() {
			let da = new Date();
			let str =
				'' +
				da.getFullYear() +
				this.getStr(da.getMonth() + 1) +
				this.getStr(da.getDate()) +
				this.getStr(da.getHours()) +
				this.getStr(da.getMinutes()) +
				this.getStr(da.getSeconds());
			return str;
		},
		getStr(val) {
			if (val < 10) {
				return '0' + val;
			} else {
				return val;
			}
		}
	}
};
</script>

<style scoped lang="scss">
.main {
	padding: 60rpx 30rpx;
}
.input_box {
	border: 1px solid #f5f5f5;
	border-radius: 10rpx;
	overflow: hidden;
	padding: 16rpx;
}
.btn {
	background-color: var(--color);
	color: #fff;
	border-radius: 10rpx;
	text-align: center;
	line-height: 80rpx;
	margin: 120rpx 60rpx 0;
}
</style>
